<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="chrome=1;IE=edge">
    <meta name="viewport" content="user-scalable=no">
    <!-- vue2 -->
    <script src="/examples/js/vue.min.js"></script>
    <!-- 示例演示-公共样式 -->
    <link rel="stylesheet" href="/examples/css/railView.css" type="text/css" />
    <!-- 引入element-ui组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <!-- 引入element-ui样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- RailUnit 插件 -->
    <script type="text/javascript" src="/RailUnit/RailUnit.umd.js" charset="utf-8"></script>
</head>
<body>
    <div id="app">
        <div id="buttom-container">
            <el-button type="info" @click="showCard = true">点标注</el-button>
            <el-button type="info" @click="handleDelete">删除绘制</el-button>
        </div>
        <div id="viewer" style="width:100%;height:100%;position:relative;float:left"></div>
        <el-card class="box-card" v-show="showCard" style="width: 400px;">
            <div slot="header" class="clearfix">
              <span>点标注设置</span>
              <el-button class="close-btn" type="text" @click="showCard = false">×</el-button>
            </div>
            <div class="card-container">
                <el-form 
                    ref="form" 
                    :model="formValues" 
                    label-width="80px"
                >
                    <el-form-item label="颜色：">
                        <el-color-picker v-model.number="formValues.color"></el-color-picker>
                    </el-form-item>
                    <el-form-item label="点大小：">
                        <el-input v-model.number="formValues.pointSize"></el-input>
                    </el-form-item>
                </el-form>
                <div class="modal-footer">
                    <el-button size="small" type="primary" @click="handleSavePoint">保存设置</el-button>
                    <el-button size="small" type="primary" @click="handleActivate" :disabled="activate">激活绘制</el-button>
                    <el-button size="small" type="primary" @click="handleCancel">取消绘制</el-button>
                    <el-button size="small" type="primary" @click="handleEmpty" >清空绘制</el-button>
                </div>
            </div>
        </el-card>
    </div>
    
    <script id="viewerStartup" type="module">
        const vm = new Vue({
            el: '#app',
            data: {
                bimViewer: null,
                showCard: false,
                activate: true,
                drawRes: null,
                drawArr: {},
                formValues: {
                    color: 'red',
                    pointSize: 2,
                }
            },
            mounted() {
                this.bimViewerFn()
            },
            methods: {
                // 初始化模型
                bimViewerFn() {
                    this.bimViewer = new MyViewer({
                        serverUrl: '/RailUnit/',
                        containerElement: document.getElementById('viewer'),
                        nodeVisible: false
                    })
                    this.bimViewer.loadModel2('jianzhu')
                },
                // 保存设置
                handleSavePoint() {
                    const { color, pointSize } = this.formValues
                    console.log(this.formValues, '参数');
                    // const red = Number('0x' + hex.substring(1, 3));
                    // const green = Number('0x' + hex.substring(3, 5));
                    // const blue = Number('0x' + hex.substring(5, 7));
                    // const rgb = {r: red, g: green, b: blue}; // 颜色

                    this.drawRes = this.bimViewer.setDrawing('point', {
                        stroke: color,
                        pointSize: pointSize,
                    });
                    this.activate = false
                },
                // 激活绘制
                handleActivate() {
                    this.bimViewer.acactivationDrawing(this.drawRes)
                },
                // 取消绘制
                handleCancel() {
                    console.log(this.drawRes, '取消绘制');
                    this.drawArr = this.bimViewer.deactiveDrawing(this.drawRes)
                },
                // 清空绘制
                handleEmpty() {
                    this.bimViewer.clearIndication()
                },
                // 删除绘制
                handleDelete () {
                    // this.drawArr.forEach(item=>{
                    //     this.bimViewer.deleteDrawing(item.uniqueId)
                    // })
                    this.bimViewer.deleteDrawing(this.drawRes)
                }
            }
        })
    </script>
</body>
</html>
